/**
 * 
 */
package com.demo2do.fms.admin.entity.search.business;

import java.util.Date;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

/**
 * 回单确认查询
 * 
 * @author Ysy
 *
 */
public class TransOrderSearch implements QueryBuilder{
    
    /** 所选择公司 */
    private Long organizationId;
    
    /** 派车单号 */
    private String dispatchOrderCode;
    
    /** 驳运车号 */
    private Long vehicleId;
    
    /** 安吉调度指令组号 */
    private String shipmentGroupId;
    
    /** 起始地 装卸地 */
    private Long startFacilityId;
    
    /** 目的地 装卸地 */
    private Long destinationFacilityId;
    
    /** 开始派车单日期 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginDispatchDate;
    
    /** 结束派车单日期 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDispatchDate;
    
    /** 主驾驶员 */
    private Long mainDriverId;
    
    /** 第一副驾驶员 */
    private Long firstViceDriverId;
    
    /** 是否隐藏全部回单的派车单  */
    private Boolean accomplishConfirm;
    
    private QueryOrder queryOrder;
    
    private QueryFilter queryFilter;

    /**
     * 
     * the default constructor
     */
    public TransOrderSearch() {
        queryOrder = new QueryOrder();
    }
    
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {
        
        if(queryFilter == null || refresh) {

            queryFilter = new QueryFilter().addEquals("organizationId", organizationId)
                                           .addEquals("code", dispatchOrderCode)
                                           .addEquals("vehicleId", vehicleId)
                                           .addEquals("shipmentGroupId", shipmentGroupId)
                                           .addEquals("startFacilityId", startFacilityId)
                                           .addEquals("destinationFacilityId", destinationFacilityId)
                                           .addDateTimeBetween("dispatchDate", beginDispatchDate, endDispatchDate)
                                           .addEquals("mainDriverId", mainDriverId)
                                           .addEquals("firstViceDriverId", firstViceDriverId)
                                           .addEquals("accomplishConfirm", accomplishConfirm);
        }
        
        return queryFilter;
    }
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return queryOrder;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM DispatchOrder WHERE actualLoadNumber > 0 AND disabled = false " + getPreparedFilter(false).clauseSentence() + queryOrder.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
    /**
     * @return the organizationId
     */
    public Long getOrganizationId() {
        return organizationId;
    }

    /**
     * @return the dispatchOrderCode
     */
    public String getDispatchOrderCode() {
        return dispatchOrderCode;
    }

    /**
     * @return the vehicleId
     */
    public Long getVehicleId() {
        return vehicleId;
    }

    /**
     * @return the shipmentGroupId
     */
    public String getShipmentGroupId() {
        return shipmentGroupId;
    }

    /**
     * @return the startFacilityId
     */
    public Long getStartFacilityId() {
        return startFacilityId;
    }

    /**
     * @return the destinationFacilityId
     */
    public Long getDestinationFacilityId() {
        return destinationFacilityId;
    }

    /**
     * @return the beginDispatchDate
     */
    public Date getBeginDispatchDate() {
        return beginDispatchDate;
    }

    /**
     * @return the endDispatchDate
     */
    public Date getEndDispatchDate() {
        return endDispatchDate;
    }

    /**
     * @return the mainDriverId
     */
    public Long getMainDriverId() {
        return mainDriverId;
    }

    /**
     * @return the firstViceDriverId
     */
    public Long getFirstViceDriverId() {
        return firstViceDriverId;
    }

    /**
     * @return the accomplishConfirm
     */
    public Boolean getAccomplishConfirm() {
        return accomplishConfirm;
    }

    /**
     * @param organizationId the organizationId to set
     */
    public void setOrganizationId(Long organizationId) {
        this.organizationId = organizationId;
    }

    /**
     * @param dispatchOrderCode the dispatchOrderCode to set
     */
    public void setDispatchOrderCode(String dispatchOrderCode) {
        this.dispatchOrderCode = StringUtils.trim(dispatchOrderCode);
    }

    /**
     * @param vehicleId the vehicleId to set
     */
    public void setVehicleId(Long vehicleId) {
        this.vehicleId = vehicleId;
    }

    /**
     * @param shipmentGroupId the shipmentGroupId to set
     */
    public void setShipmentGroupId(String shipmentGroupId) {
        this.shipmentGroupId = shipmentGroupId;
    }

    /**
     * @param startFacilityId the startFacilityId to set
     */
    public void setStartFacilityId(Long startFacilityId) {
        this.startFacilityId = startFacilityId;
    }

    /**
     * @param destinationFacilityId the destinationFacilityId to set
     */
    public void setDestinationFacilityId(Long destinationFacilityId) {
        this.destinationFacilityId = destinationFacilityId;
    }

    /**
     * @param beginDispatchDate the beginDispatchDate to set
     */
    public void setBeginDispatchDate(Date beginDispatchDate) {
        this.beginDispatchDate = beginDispatchDate;
    }

    /**
     * @param endDispatchDate the endDispatchDate to set
     */
    public void setEndDispatchDate(Date endDispatchDate) {
        this.endDispatchDate = endDispatchDate;
    }

    /**
     * @param mainDriverId the mainDriverId to set
     */
    public void setMainDriverId(Long mainDriverId) {
        this.mainDriverId = mainDriverId;
    }

    /**
     * @param firstViceDriverId the firstViceDriverId to set
     */
    public void setFirstViceDriverId(Long firstViceDriverId) {
        this.firstViceDriverId = firstViceDriverId;
    }

    /**
     * @param accomplishConfirm the accomplishConfirm to set
     */
    public void setAccomplishConfirm(Boolean accomplishConfirm) {
        this.accomplishConfirm = accomplishConfirm;
    }
    
}